Repetier-Firmware  1.0.0
uiconfig.h
Go to the documentation of this file.
1 /*
2  This file is part of Repetier-Firmware.
3 
4  Repetier-Firmware is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Repetier-Firmware is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 
19 /* ===================== IMPORTANT ========================
20 
21 The LCD and Key support is new. I tested everything as good as possible,
22 but some combinations may not work as supposed.
23 The I2C methods rely on a stable I2C connection. Noise may cause wrong signals
24 which can cause the firmware to freeze.
25 
26 The ui adds quite some code, so AVRs with 64kB ram (Sanguino, Gen6) can not handle all features
27 of the firmware at the same time. You have to disable some features to gain the
28 ram needed. What should work:
29 - No sd card - the sd card code is quite large.
30 - No keys attached - The longest part is the menu handling.
31 - EEPROM_MODE 0 .
32 
33 Currently supported hardware:
34 
35 *** Displays ***
36 
37 - direct connected lcd with 4 data lines
38 - connected via i2c
39 
40 *** Keys ***
41 
42 - rotary encoder
43 - push button
44 - key matrix up to 4x4
45 - rotary encoder via i2c (only slow turns are captured correct)
46 - push button via i2c
47 
48 *** Buzzer ***
49 
50 - directly connected, high = on
51 - connected via i2c, low = on
52 
53 ==============================================================*/
54 
55 #ifndef _ui_config_h
56 #define _ui_config_h
57 
68 #define UI_DISPLAY_CHARSET 2
69 
75 #ifndef BEEPER_TYPE
76 #define BEEPER_TYPE 1
77 #define BEEPER_TYPE_INVERTING false
78 #endif
79 
80 #if BEEPER_TYPE==1 && !defined(BEEPER_PIN)
81 #define BEEPER_PIN 37
82 #endif
83 #if BEEPER_TYPE==2
84 #define BEEPER_ADDRESS 0x40 // I2C address of the chip with the beeper pin
85 #define BEEPER_PIN _BV(7) // Bit value for pin 8
86 #define COMPILE_I2C_DRIVER // We need the I2C driver as we are using i2c
87 #endif
88 
89 
101 #define UI_DISPLAY_TYPE 5
102 
103 #if UI_DISPLAY_TYPE == DISPLAY_U8G // Special case for graphic displays
104 
105 // You need to define which controller you use and set pins accodringly
106 
107 // For software spi assign these definitions
108 // SCK Pin: UI_DISPLAY_D4_PIN
109 // Mosi Pin: UI_DISPLAY_ENABLE_PIN
110 // CD Pin: UI_DISPLAY_RS_PIN
111 
112 // ST7920 with software SPI
113 #define U8GLIB_ST7920
114 // SSD1306 with software SPI
115 //#define U8GLIB_SSD1306_SW_SPI
116 // SH1106 with software SPI
117 // U8GLIB_SH1106_SW_SPI
118 // SSD1306 over I2C using hardware I2C pins
119 // #define U8GLIB_MINI12864_2X_SW_SPI
120 //#define U8GLIB_SSD1306_I2C
121 // For the 8 bit ks0108 display you need to set these pins
122 // UI_DISPLAY_D0_PIN,UI_DISPLAY_D1_PIN,UI_DISPLAY_D2_PIN,UI_DISPLAY_D3_PIN,UI_DISPLAY_D4_PIN,UI_DISPLAY_D5_PIN,UI_DISPLAY_D6_PIN,UI_DISPLAY_D7_PIN
123 // UI_DISPLAY_ENABLE_PIN,UI_DISPLAY_CS1,UI_DISPLAY_CS2,
124 // UI_DISPLAY_DI,UI_DISPLAY_RW_PIN,UI_DISPLAY_RESET_PIN
125 //#define U8GLIB_KS0108
126 //#define U8GLIB_KS0108_FAST
127 // UI_DISPLAY_RS_PIN = CS
128 // UI_DISPLAY_D5_PIN = A0
129 //#define U8GLIB_ST7565_NHD_C2832_HW_SPI
130 
131 #define UI_LCD_WIDTH 128
132 #define UI_LCD_HEIGHT 64
133 
134 //select font size
135 #define UI_FONT_6X10 //default font
136 #ifdef UI_FONT_6X10
137 #define UI_FONT_WIDTH 6
138 #define UI_FONT_HEIGHT 10
139 #define UI_FONT_SMALL_HEIGHT 7
140 #define UI_FONT_DEFAULT repetier_6x10
141 #define UI_FONT_SMALL repetier_5x7
142 #define UI_FONT_SMALL_WIDTH 5 //smaller font for status display
143 #endif
144 
145 //calculate rows and cols available with current font
146 #define UI_COLS (UI_LCD_WIDTH/UI_FONT_WIDTH)
147 #define UI_ROWS (UI_LCD_HEIGHT/UI_FONT_HEIGHT)
148 #undef UI_DISPLAY_CHARSET
149 #define UI_DISPLAY_CHARSET 3
150 #else
151 
154 #define UI_COLS 20
155 
158 #define UI_ROWS 4
159 #endif // UI_DISPLAY_TYPE
160 
161 /* What type of chip is used for I2C communication
162 0 : PCF8574 or PCF8574A or compatible chips.
163 1 : MCP23017
164 */
165 #define UI_DISPLAY_I2C_CHIPTYPE 0
166 // 0x40 till 0x4e for PCF8574, 0x40 for the adafruid RGB shield, 0x40 - 0x4e for MCP23017
167 // Official addresses have a value half as high!
168 #define UI_DISPLAY_I2C_ADDRESS 0x4e
169 // For MCP 23017 define which pins should be output
170 #define UI_DISPLAY_I2C_OUTPUT_PINS 65504
171 // Set the output mask that is or'd over the output data. This is needed to activate
172 // a backlight switched over the I2C.
173 // The adafruit RGB shields enables a light if the bit is not set. Bits 6-8 are used for backlight.
174 #define UI_DISPLAY_I2C_OUTPUT_START_MASK 0
175 // For MCP which inputs are with pullup. 31 = pins 0-4 for adafruid rgb shield buttons
176 #define UI_DISPLAY_I2C_PULLUP 31
177 /* How fast should the I2C clock go. The PCF8574 work only with the lowest setting 100000.
178 A MCP23017 can run also with 400000 Hz */
179 #define UI_I2C_CLOCKSPEED 100000L
180 
183 #if UI_DISPLAY_TYPE == DISPLAY_I2C // I2C Pin configuration
184 #define UI_DISPLAY_RS_PIN _BV(4)
185 #define UI_DISPLAY_RW_PIN _BV(5)
186 #define UI_DISPLAY_ENABLE_PIN _BV(6)
187 #define UI_DISPLAY_D0_PIN _BV(0)
188 #define UI_DISPLAY_D1_PIN _BV(1)
189 #define UI_DISPLAY_D2_PIN _BV(2)
190 #define UI_DISPLAY_D3_PIN _BV(3)
191 #define UI_DISPLAY_D4_PIN _BV(0)
192 #define UI_DISPLAY_D5_PIN _BV(1)
193 #define UI_DISPLAY_D6_PIN _BV(2)
194 #define UI_DISPLAY_D7_PIN _BV(3)
195 
196 // uncomment if your using led to indicated the bed is hot
197 //#define UI_I2C_HEATBED_LED _BV(8)
198 
199 // uncomment if your using led to indicated the extruder is hot
200 //#define UI_I2C_HOTEND_LED _BV(7)
201 
202 // uncomment if your using led to indicated the FAN is on
203 //#define UI_I2C_FAN_LED _BV(6)
204 
205 // Pins for adafruid RGB shield
206 /*#define UI_DISPLAY_RS_PIN _BV(15)
207 #define UI_DISPLAY_RW_PIN _BV(14)
208 #define UI_DISPLAY_ENABLE_PIN _BV(13)
209 #define UI_DISPLAY_D0_PIN _BV(12)
210 #define UI_DISPLAY_D1_PIN _BV(11)
211 #define UI_DISPLAY_D2_PIN _BV(10)
212 #define UI_DISPLAY_D3_PIN _BV(9)
213 #define UI_DISPLAY_D4_PIN _BV(12)
214 #define UI_DISPLAY_D5_PIN _BV(11)
215 #define UI_DISPLAY_D6_PIN _BV(10)
216 #define UI_DISPLAY_D7_PIN _BV(9)*/
217 
218 #else // Direct display connections
219 #define UI_DISPLAY_RS_PIN 63 // PINK.1, 88, D_RS
220 #define UI_DISPLAY_RW_PIN -1
221 #define UI_DISPLAY_ENABLE_PIN 65 // PINK.3, 86, D_E
222 #define UI_DISPLAY_D0_PIN 59 // PINF.5, 92, D_D4
223 #define UI_DISPLAY_D1_PIN 64 // PINK.2, 87, D_D5
224 #define UI_DISPLAY_D2_PIN 44 // PINL.5, 40, D_D6
225 #define UI_DISPLAY_D3_PIN 66 // PINK.4, 85, D_D7
226 #define UI_DISPLAY_D4_PIN 59 // PINF.5, 92, D_D4
227 #define UI_DISPLAY_D5_PIN 64 // PINK.2, 87, D_D5
228 #define UI_DISPLAY_D6_PIN 44 // PINL.5, 40, D_D6
229 #define UI_DISPLAY_D7_PIN 66 // PINK.4, 85, D_D7
230 #define UI_DELAYPERCHAR 50
231 
232 // Special pins for some u8g driven display
233 
234 #define UI_DISPLAY_CS1 59
235 #define UI_DISPLAY_CS2 59
236 #define UI_DISPLAY_DI 59
237 #define UI_DISPLAY_RW_PIN 59
238 #define UI_DISPLAY_RESET_PIN 59
239 #endif
240 
241 
247 #undef UI_HAS_KEYS
248 #define UI_HAS_KEYS 1
249 
250 
256 #define UI_HAS_BACK_KEY 1
257 
258 /* Then you have the next/previous keys more like up/down keys, it may be more intuitive to change the direction you skip through the menus.
259 If you set it to true, next will go to previous menu instead of the next menu.
260 
261 */
262 #define UI_INVERT_MENU_DIRECTION 0
263 
265 //#define UI_HAS_I2C_KEYS
266 
267 // Do you have a I2C connected encoder?
268 #define UI_HAS_I2C_ENCODER 0
269 
270 // Under which address can the key status requested. This is the address of your PCF8574 where the keys are connected.
271 // If you use a MCP23017 the address from display is used also for keys.
272 #define UI_I2C_KEY_ADDRESS 0x40
273 
274 
275 #ifdef UI_MAIN
276 /* #######################################################################
277  Key definitions
278 
279 The firmware is very flexible regarding your input methods. You can use one
280 or more of the predefined key macros, to define a mapper. If no matching mapper
281 is available, you can add you c-code for mapping directly into the keyboard
282 routines. The predefined macros do the same, just hiding the code behind it.
283 
284 For each key, two seperate parts must be defined. The first is the initialization
285 which must be added inside uiInitKeys() and the second ist a testing routine.
286 These come into uiCheckKeys() or uiCheckSlowKeys() depending on the time needed
287 for testing. If you are in doubt, put it in uiCheckSlowKeys().
288 uiInitKeys() is called from an interrupt controlling the extruder, so only
289 fast tests should be put there.
290 The detect methods need an action identifier. A list of supported ids is found
291 at the beginning of ui.h It's best to use the symbol name, in case the value changes.
292 
293 1. Simple push button connected to gnd if closed on a free arduino pin
294  init -> UI_KEYS_INIT_BUTTON_LOW(pinNumber);
295  detect -> UI_KEYS_BUTTON_LOW(pinNumber,action);
296 
297 2. Simple push button connected to 5v if closed on a free arduino pin
298  init -> UI_KEYS_INIT_BUTTON_HIGH(pinNumber);
299  detect -> UI_KEYS_BUTTON_HIGH(pinNumber,action);
300 
301 3. Click encoder, A/B connected to gnd if closed.
302  init -> UI_KEYS_INIT_CLICKENCODER_LOW(pinA,pinB);
303  detect -> UI_KEYS_CLICKENCODER_LOW(pinA,pinB);
304  or UI_KEYS_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
305  If you can move the menu cursor without a click, just be adding some force in one direction,
306  toggle the _REV with non _REV and toggle pins.
307  If the direction is wrong, toggle _REV with non _REV version.
308  For the push button of the encoder use 1.
309 
310 4. Click encoder, A/B connected to 5V if closed.
311  init -> UI_KEYS_INIT_CLICKENCODER_HIGH(pinA,pinB);
312  detect -> UI_KEYS_CLICKENCODER_HIGH(pinA,pinB);
313  or UI_KEYS_CLICKENCODER_HIGH_REV(pinA,pinB); // reverse direction
314  If you can move the menu cursor without a click, just be adding some force in one direction,
315  toggle the _REV with non _REV and toggle pins.
316  If the direction is wrong, toggle _REV with non _REV version.
317  For the push button of the encoder use 2.
318 
319 5. Maxtrix keyboard with 1-4 rows and 1-4 columns.
320  init -> UI_KEYS_INIT_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
321  detect -> UI_KEYS_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
322  In addition you have to set UI_MATRIX_ACTIONS to match your desired actions.
323 
324 ------- Keys connected via I2C -------------
325 
326 All keys and the buzzer if present must be on a connected to a single PCF8574 chip!
327 As all I2C request take time, they belong all in uiCheckSlowKeys.
328 Dont use the pin ids but instead _BV(pinNumber0_7) as pin id. 0 = First pin
329 
330 6. Click encoder, A/B connected to gnd if closed.
331  init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
332  detect -> UI_KEYS_I2C_CLICKENCODER_LOW(pinA,pinB);
333  or UI_KEYS_I2C_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
334  If you can move the menu cursor without a click, just be adding some force in one direction,
335  toggle the _REV with non _REV and toggle pins.
336  If the direction is wrong, toggle _REV with non _REV version.
337  For the push button of the encoder use 7.
338  NOTICE: The polling frequency is limited, so only slow turns are captured correct!
339 
340 7. Simple push button connected to gnd if closed via I2C on a PCF8574
341  init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
342  detect -> UI_KEYS_I2C_BUTTON_LOW(pinNumber,action);
343 
344 -------- Some notes on actions -------------
345 
346 There are three kinds of actions.
347 
348 Type 1: Immediate actions - these are execute and forget actions like home/pre-heat
349 Type 2: Parameter change action - these change the mode for next/previous keys. They are valid
350  until a new change action is initiated or the action is finished with ok button.
351 Type 3: Show menu action. These actions have a _MENU_ in their name. If they are executed, a new
352  menu is pushed on the menu stack and you see the menu. If you assign these actions directly
353  to a key, you might not want this pushing behaviour. In this case add UI_ACTION_TOPMENU to the
354  action, like UI_ACTION_TOPMENU+UI_ACTION_MENU_XPOSFAST. That will show the menu as top-menu
355  closing all othe submenus that were open.
356 
357  ####################################################################### */
358 
359 // Use these codes for key detect. The main menu will show the pressed action in the lcd display.
360 // after that assign the desired codes.
361 //#define UI_MATRIX_ACTIONS {2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015}
362 // Define your matrix actions
363 #define UI_MATRIX_ACTIONS {UI_ACTION_HOME_ALL, UI_ACTION_TOP_MENU, UI_ACTION_SET_ORIGIN, UI_ACTION_NEXT,\
364  UI_ACTION_HOME_Z, UI_ACTION_MENU_ZPOS, UI_ACTION_COOLDOWN, UI_ACTION_OK,\
365  UI_ACTION_HOME_Y, UI_ACTION_MENU_YPOSFAST, UI_ACTION_PREHEAT_ALL, UI_ACTION_PREVIOUS,\
366  UI_ACTION_HOME_X, UI_ACTION_MENU_XPOSFAST, UI_ACTION_DISABLE_STEPPER, UI_ACTION_BACK}
367 #ifdef UI_MATRIX_ACTIONS
368 const int matrixActions[] PROGMEM = UI_MATRIX_ACTIONS;
369 #endif
370 
371 void uiInitKeys() {
372 #if UI_HAS_KEYS!=0
373  //UI_KEYS_INIT_CLICKENCODER_LOW(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
374  UI_KEYS_INIT_BUTTON_LOW(4); // push button, connects gnd to pin
379 
380 // UI_KEYS_INIT_CLICKENCODER_LOW(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
381 // UI_KEYS_INIT_BUTTON_LOW(43); // push button, connects gnd to pin
382 // UI_KEYS_INIT_MATRIX(32,47,45,43,41,39,37,35);
383 #endif
384 }
385 void uiCheckKeys(uint16_t &action) {
386 #if UI_HAS_KEYS!=0
387 
388  //UI_KEYS_CLICKENCODER_LOW_REV(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
389  UI_KEYS_BUTTON_LOW(4,UI_ACTION_OK); // push button, connects gnd to pin
390  UI_KEYS_BUTTON_LOW(5,UI_ACTION_NEXT); // push button, connects gnd to pin
391  UI_KEYS_BUTTON_LOW(6,UI_ACTION_PREVIOUS); // push button, connects gnd to pin
392  UI_KEYS_BUTTON_LOW(11,UI_ACTION_BACK); // push button, connects gnd to pin
393  UI_KEYS_BUTTON_LOW(42,UI_ACTION_SD_PRINT ); // push button, connects gnd to pin
394 // UI_KEYS_CLICKENCODER_LOW_REV(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
395 // UI_KEYS_BUTTON_LOW(43,UI_ACTION_OK); // push button, connects gnd to pin
396 #endif
397 }
398 inline void uiCheckSlowEncoder() {
399 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
400 #if UI_DISPLAY_I2C_CHIPTYPE==0
402  uint8_t keymask = HAL::i2cReadNak(); // Read current key mask
403 #endif
404 #if UI_DISPLAY_I2C_CHIPTYPE==1
406  HAL::i2cWrite(0x12); // GIOA
407  HAL::i2cStop();
409  uint16_t keymask = HAL::i2cReadAck();
410  keymask = keymask + (HAL::i2cReadNak()<<8);
411 #endif
412  HAL::i2cStop();
413  // Add I2C click encoder tests here, all other i2c tests and a copy of the encoder test belog in uiCheckSlowKeys
414  UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
415 #endif
416 }
417 void uiCheckSlowKeys(uint16_t &action) {
418 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
419 #if UI_DISPLAY_I2C_CHIPTYPE==0
421  uint8_t keymask = HAL::i2cReadNak(); // Read current key mask
422 #endif
423 #if UI_DISPLAY_I2C_CHIPTYPE==1
425  HAL::i2cWrite(0x12); // GPIOA
426  HAL::i2cStop();
428  uint16_t keymask = HAL::i2cReadAck();
429  keymask = keymask + (HAL::i2cReadNak()<<8);
430 #endif
431  HAL::i2cStop();
432  // Add I2C key tests here
433  UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
434  UI_KEYS_I2C_BUTTON_LOW(_BV(1),UI_ACTION_OK); // push button, connects gnd to pin
435  UI_KEYS_I2C_BUTTON_LOW(_BV(3),UI_ACTION_BACK); // push button, connects gnd to pin
436  UI_KEYS_I2C_BUTTON_LOW(_BV(4),UI_ACTION_MENU_QUICKSETTINGS+UI_ACTION_TOPMENU); // push button, connects gnd to pin
437  UI_KEYS_I2C_BUTTON_LOW(_BV(5),UI_ACTION_MENU_EXTRUDER+UI_ACTION_TOPMENU); // push button, connects gnd to pin
438  UI_KEYS_I2C_BUTTON_LOW(_BV(6),UI_ACTION_MENU_POSITIONS+UI_ACTION_TOPMENU); // push button, connects gnd to pin
439 /*
440  // Button handling for the Adafruit RGB shild
441  UI_KEYS_I2C_BUTTON_LOW(4,UI_ACTION_PREVIOUS); // Up button
442  UI_KEYS_I2C_BUTTON_LOW(8,UI_ACTION_NEXT); // down button
443  UI_KEYS_I2C_BUTTON_LOW(16,UI_ACTION_BACK); // left button
444  UI_KEYS_I2C_BUTTON_LOW(2,UI_ACTION_OK); // right button
445  UI_KEYS_I2C_BUTTON_LOW(1,UI_ACTION_MENU_QUICKSETTINGS); //Select button
446  // ----- End RGB shield ----------
447  */
448 #endif
449 
450  //UI_KEYS_MATRIX(32,47,45,43,41,39,37,35);
451 }
452 
453 #endif
454 #endif
455 
456 
457 
static void i2cStop(void)
Definition: HAL.cpp:459
#define UI_KEYS_I2C_BUTTON_LOW(pin, action_)
Definition: ui.h:411
static uint8_t i2cReadNak(void)
Definition: HAL.cpp:506
void uiCheckSlowEncoder()
Definition: gameduino2.h:167
#define UI_KEYS_INIT_BUTTON_LOW(pin)
Definition: ui.h:365
#define UI_KEYS_BUTTON_LOW(pin, action_)
Definition: ui.h:371
#define I2C_READ
Definition: HAL.h:144
#define UI_ACTION_MENU_POSITIONS
Definition: ui.h:282
static void i2cWrite(uint8_t data)
Definition: HAL.cpp:475
void uiCheckSlowKeys(int &action)
Definition: gameduino2.h:168
#define UI_ACTION_NEXT
Definition: ui.h:61
#define UI_ACTION_MENU_QUICKSETTINGS
Definition: ui.h:280
#define UI_ACTION_TOPMENU
Definition: ui.h:58
static uint8_t i2cReadAck(void)
Definition: HAL.cpp:494
#define UI_ACTION_BACK
Definition: ui.h:82
#define UI_DISPLAY_I2C_ADDRESS
Definition: uiconfig.h:168
void uiCheckKeys(int &action)
Definition: gameduino2.h:166
#define I2C_WRITE
Definition: HAL.h:146
const int8_t sensitive_pins [] PROGMEM
Definition: Commands.cpp:24
#define UI_KEYS_I2C_CLICKENCODER_LOW_REV(pinA, pinB)
Definition: ui.h:410
#define UI_ACTION_OK
Definition: ui.h:83
#define UI_I2C_KEY_ADDRESS
Definition: uiconfig.h:272
void uiInitKeys()
Definition: gameduino2.h:165
#define UI_ACTION_SD_PRINT
Definition: ui.h:94
static void i2cStartWait(uint8_t address)
Definition: HAL.cpp:415
#define UI_ACTION_MENU_EXTRUDER
Definition: ui.h:281
#define UI_ACTION_PREVIOUS
Definition: ui.h:62